using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Champ
{
    class Menu
    {
        private static int MAX = 10;    // maximum number of menuItems allowed (10)
        private int menuItemCount;      //the total count of menuItems
        private int curMenuItem;        //currently selected menuItem index
        private string[] menuItems;     //variable that holds all the string of whatever you want your menu items to be called
        private Vector2[] pos;          //position of each menu item
        private double[] scale;         //scale of each menu item
        private Color unselected;       //unselected color of your menuItem
        private Color selected;         //selected color of your menuItem
        private SpriteFont font;        //text that will be used by this menu

        public Menu(Color unslectedColor, Color selectedColor, SpriteFont sp) //Constructor to initalize variables

        {
            font = sp;
            menuItems = new string[MAX];
            pos = new Vector2[MAX];
            scale = new double[MAX];
            unselected = unslectedColor;
            selected = selectedColor;
            menuItemCount = 0;
            curMenuItem = 0;
        }

        public void addMenuItem(string name, Vector2 p) //allows you to add menu items to the class
        {
            if (menuItemCount < MAX)
            {
                menuItems[menuItemCount] = name;
                scale[menuItemCount] = 1.0f;
                pos[menuItemCount++] = p;
            }
        }

        public void selectNext()    //select next
        {
            if (curMenuItem < menuItemCount - 1)
            {
                curMenuItem++;
            }
            else
            {
                curMenuItem = 0;
            }
        }

        public void selectPrev()    //select previous
        {
            if (curMenuItem > 0)
            {
                curMenuItem--;
            }
            else
            {
                curMenuItem = menuItemCount - 1;
            }
        }
        public int getSelectedNum()
        {
            return curMenuItem;
        }

        public string getSelectedName()
        {
            return menuItems[curMenuItem];
        }

        public void update(GameTime gameTime)  //grows or shrinks selected object
        {
            for (int x = 0; x < menuItemCount; x++)
            {
                if (x == curMenuItem)
                {
                    if (scale[x] < 2.0f)
                    {
                        scale[x] += 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
                    }
                }
                else if (scale[x] > 1.0f && x != curMenuItem)
                {
                    scale[x] -= 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch) //adjusts itelf based on the size of the font and the scale
        {
            spriteBatch.Begin();
            for (int x = 0; x < menuItemCount; x++)
            {
                if (x == curMenuItem)
                {
                    Vector2 p = pos[x];
                    p.X -= (float)(22 * scale[x] / 2);
                    p.Y -= (float)(22 * scale[x] / 2);
                    spriteBatch.DrawString(font, menuItems[x], p, selected, 0.0f, new Vector2(0, 0), (float)scale[x], SpriteEffects.None, 0);
                }
                else
                {
                    Vector2 p = pos[x];
                    p.X -= (float)(22 * scale[x] / 2);
                    p.Y -= (float)(22 * scale[x] / 2);
                    spriteBatch.DrawString(font, menuItems[x], p, unselected, 0.0f, new Vector2(0, 0), (float)scale[x], SpriteEffects.None, 0);
                }
            }
            spriteBatch.End();
        }


    }
}